package jacky.com.androidtestdemo.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Toast;


import jacky.com.androidtestdemo.R;

public class ProgressBar extends Activity {

    private android.widget.ProgressBar barA;
    private android.widget.ProgressBar barB;

    private Handler hd = new Handler(){

        @Override
        public void handleMessage(Message msg) {

            barA.setProgress(msg.arg1);
            if(msg.arg1 == 100){

            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress_bar);

        initVar();
    }

    private void initVar() {
        barA = (android.widget.ProgressBar) findViewById(R.id.barA);
        barB = (android.widget.ProgressBar) findViewById(R.id.barB);
    }


    public void onClickButton(View v){
        barA.setVisibility(View.VISIBLE);
        barB.setVisibility(View.VISIBLE);

        ra.start();
    }

    Thread ra = new Thread(new Runnable() {

        int num = 0;
        @Override
        public void run() {
//            Log.d("TAG", "start thread");

            num += 10;
//            try {
//                Thread.sleep(2000);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }

            Message msg = hd.obtainMessage();
            msg.arg1 = num;

            Log.d("TAG", String.valueOf(num));
            if(num > 100){
                hd.removeCallbacks(ra);
            }
            else{
                hd.sendMessage(msg);

                hd.postDelayed(ra, 1500);
            }
        }
    });


}
